import {
  checkLogin
} from './auth.js'
new Vue({
  el: '#app',
  data: {
    IS_LOGIN: null,
    dataList: [],
    pagination: {
      queryString: '',
      currentPage: 1,
      pageSize: 5,
      total: 0
    }
  },
  async created() {
    this.IS_LOGIN = await checkLogin()
    if (this.IS_LOGIN == null) {
      location.href = '/'
    }
    await this.getUserPageList()
  },
  mounted() {
    
  },
  methods: {
    // 获取用户分页数据
    async getUserPageList() {
      const res = await request.get('/user/pageQuery',{
        params: {
          queryString: this.pagination.queryString,
          currentPage: this.pagination.currentPage,
          pageSize: this.pagination.pageSize
        }
      })
      console.log(res)
      this.dataList = res.data.list
      this.pagination.total = res.data.pageTotal
    },
    // 每页数量改变
    handleSizeChange(pageSize) {
      this.pagination.pageSize = pageSize
      this.getUserPageList()
    },
    // 页码改变
    handleCurrentChange(currentPage) {
      this.pagination.currentPage = currentPage
      this.getUserPageList()
    },
    // 状态改变
    async handleStatusChange(row) {
      console.log('状态改变', row);
      const res = await request.put(`/user/changeStatus/${row.uid}/${row.isDelete}`)
      console.log(res);
      this.getUserPageList()
    }
  }
})